package ltd.nullpointer.frontend.model.entity.up;

import com.boot2.core.LongBaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;
import ltd.nullpointer.tcp.core.annotation.TcpUpMessage;
import ltd.nullpointer.tcp.core.annotation.TcpUpOffset;
import ltd.nullpointer.tcp.core.constant.TCPEnum.ResolveType;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

import javax.persistence.Entity;
import javax.persistence.Table;
import java.math.BigDecimal;
import java.util.Date;

/**
 * @author zhangweilin
 * @Description: xxxxx
 * @date 2019/12/7
 */
@ApiModel("传感器数据")
@TcpUpMessage(start = 7,messageCode="AA756A",isPersistence = false)
@Data
@ToString(callSuper = true)
@Entity
@Table
@SQLDelete(sql = "update np_biz_module_heart_beat_up set is_deleted = id where id = ?")
@Where(clause = "is_deleted is false")
@DynamicInsert // 加上此注解，可以只添加有值的字段
@DynamicUpdate // 此注解，是指，会先查，然后跟参数对比，不一样的就更新，所以并不是有值更新，如果db中有值，参数里没值，那么db中的值会清空
public class ModuleHeartBeatUp extends LongBaseEntity {

    /**
     * 心跳时间
     */
    @ApiModelProperty("心跳时间")
    @TcpUpOffset(start = 1, end = 6, dateFormat = "yyMMddHHmmss")
    private Date heartBeatTime;

    /**
     * 模块标识
     */
    @ApiModelProperty("模块标识")
    @TcpUpOffset(start = 7, end = 22, resolveType = ResolveType.ascii)
    private String identification;

    /**
     * 心跳间隔时间
     */
    @ApiModelProperty("心跳间隔时间")
    @TcpUpOffset(start = 23, end = 23,resolveType =ResolveType.hexByte2Int )
    private Integer interval;

    /**
     * 传感器编号
     */
    @ApiModelProperty("传感器编号")
    @TcpUpOffset(start = 24, end = 31)
    private String sensorNo;

    /**
     * 模块温度
     */
    @ApiModelProperty("模块温度")
    @TcpUpOffset(start = 32, end = 33, calcExpression = "this*0.1M", resolveType = ResolveType.hexByte2UnsignedInt)
    private BigDecimal temp;

    /**
     * 模块电压
     */
    @ApiModelProperty("模块电压")
    @TcpUpOffset(start = 34, end = 35,calcExpression = "this*0.1M",resolveType = ResolveType.hexByte2Int)
    private BigDecimal voltage;

}